//
//  LeftTableViewController.m
//  SmileWeather
//
//  Created by lanou3g on 15/9/16.
//  Copyright (c) 2015年 陶天海. All rights reserved.
//

#import "LeftTableViewController.h"
#import "UMSocialSnsPlatformManager.h"
@interface LeftTableViewController ()
@property (nonatomic, strong) UISearchController *searchController;
@property (strong,nonatomic) NSMutableArray  *searchList;


@end

@implementation LeftTableViewController
- (void)setUpHeadView {
  _headView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kWidth/3)];
    _headView.userInteractionEnabled = YES;
    self.tableView.tableHeaderView = _headView;
  _tapImageView = [[TapImageView alloc] initWithFrame:CGRectMake(kWidth/12, kWidth/3 - kWidth/4,kWidth/4, kWidth/4) target:self action:@selector(Tap)];
    _tapImageView.image = [UIImage imageNamed:@"placeHoderImage.jpg"];
    [_headView addSubview:_tapImageView];
    
    [self setUpImageView:_tapImageView];
    
}
//设置imageView的layer
- (void)setUpImageView:(TapImageView *)imageView {
    
    //允许设置
    imageView.layer.masksToBounds = YES;
    imageView.layer.borderWidth = 2;
    imageView.layer.cornerRadius = imageView.bounds.size.height/2 ;
    imageView.layer.borderColor = [[UIColor whiteColor] CGColor];
}

- (void)setUpBlurImageView {
    BlurImageView *blurimageView = [[BlurImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.tableView.backgroundView = blurimageView;
    [self.tableView registerClass:[LeftTableViewCell class] forCellReuseIdentifier:@"leftCell"];
    self.tableView.separatorStyle =  0;

}
- (void)Tap {
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToTencent];
    
    snsPlatform.loginClickHandler(self, [UMSocialControllerService defaultControllerService], YES, ^(UMSocialResponseEntity *response) {
        
        NSLog(@"response is %@", response);
        
        // 如果是授权到新浪微博，SSO之后如果想获取用户的昵称、头像等需要再获取一次账户信息
        
        [[UMSocialDataService defaultDataService]requestSocialAccountWithCompletion:^(UMSocialResponseEntity *response) {
            
            // 打印用户昵称
            
            NSLog(@"SinaWeibo's user name is %@", [[[response.data objectForKey:@"accounts"]objectForKey:UMShareToTencent] objectForKey:@"icon"]);
            [_tapImageView removeFromSuperview];
            
            NSURL *url = [[[response.data objectForKey:@"accounts"]objectForKey:UMShareToTencent] objectForKey:@"icon"];
            [_tapImageView sd_setImageWithURL:url];
            [_headView addSubview:_tapImageView];
            
            
        }];
        
    });
    NSLog(@"被点击了!");
    


    NSLog(@"被点击了!");

}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpHeadView];
    [self setUpBlurImageView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 5;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSArray * arr = @[@"首页࿐",@"今日运势࿐",@"今日笑笑࿐",@"我的收藏࿐",@"设置࿐"];
    
    // Configure the cell..
    LeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"leftCell" forIndexPath:indexPath];
     cell.showLabelOne.text = arr[indexPath.row];    // Configure the cell...
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kWidth/4;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        [self.viewDeckController toggleLeftViewAnimated:YES];

}
    else if (indexPath.row == 1){
        FortuneViewController *fortuneVC = [[FortuneViewController alloc] init];
        UINavigationController *fortuneNaVC = [[UINavigationController alloc] initWithRootViewController:fortuneVC];
        [self presentViewController:fortuneNaVC animated:YES completion:nil];
    }
    else if (indexPath.row == 2) {
        
     LaughTabBarController *laughTabVC = [[LaughTabBarController alloc] init];
     [self presentViewController:laughTabVC animated:YES completion:nil];
 }
    else if (indexPath.row == 3) {
        MyCollectionsController *collectionVC = [[MyCollectionsController alloc] init];
        
        UINavigationController *collectNavc = [[UINavigationController alloc] initWithRootViewController:collectionVC];
        [self presentViewController:collectNavc animated:YES completion:nil];
    
    
    } else if (indexPath.row == 4) {
        SettingsController *setVC = [[SettingsController alloc] init];
        
        UINavigationController *setNavc = [[UINavigationController alloc] initWithRootViewController:setVC];
        [self presentViewController:setNavc animated:YES completion:nil];
    }
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
